package com.aote.expression.paramprocessor;

import java.util.Hashtable;
import java.util.Map;

import com.aote.expression.Param;
import com.browsesoft.dbtools.DBTools;
import com.browsesoft.htmlcomponent.HTMLBasicComponent;
import com.browsesoft.user.User;

/**
 * 
 * 榆林用能设备特殊处理（发折子打印使用
 * 
 * @author Administrator
 * 
 */
public class YongNengSheBeiShow implements ParamProcessor {

	public String process(Param param, Map attributes, User loginUser,
			HTMLBasicComponent component) throws NoFitValueException {
		// 得到用户编号和类型,根据类型获取用能设备
		String userType = (String) attributes.get("f_usertype");
		String userId = (String) attributes.get("f_userid");
		if (userType != null && userType.equals("民用")) {
			return findMY(userId);
		} else {
			return findFMY(userId);
		}

	}

	// 查找民用用户用能设备
	public String findMY(String userId) {
		String result = "";
		try {
			String sql = "select f_wallhangboiler,f_wallhangboilerbrand,f_kitchen,f_kitchenbrand,f_waterheater,f_waterheaterbrand from t_userfiles where f_userid='"
					+ userId + "'";
			String[][] datas = DBTools.executeQueryWithTableHead(sql);
			if (datas.length > 1) {
				String bigua = (String) datas[1][0];
				String biguapinpai = (String) datas[1][1];
				String zaoju = (String) datas[1][2];
				String zaojupinpai = (String) datas[1][3];
				String reshuqi = (String) datas[1][4];
				String reshuqipinpai = (String) datas[1][5];
				if (bigua != null && bigua.equals("有")) {
					result += "壁挂炉";
					if (biguapinpai != null && !biguapinpai.equals("")) {
						result += "（" + biguapinpai + ")";
					}
				}
				if (zaoju != null && zaoju.equals("有")) {
					result += " 灶具";
					if (zaojupinpai != null && !zaojupinpai.equals("")) {
						result += "（" + zaojupinpai + ")";
					}
				}
				if (reshuqi != null && reshuqi.equals("有")) {
					result += " 热水器";
					if (reshuqipinpai != null && !zaojupinpai.equals("")) {
						result += "（" + zaojupinpai + ")";
					}
				}

			}
		} catch (Exception e) {
			return "";
		}
		return result;
	}

	// 非民用用气设备信息
	public String findFMY(String userId) {
		String result = "";
		try {
			double guolu = 0;
			double huoyan = 0;
			String sql = "select * from t_userfiles where f_userid='" + userId
					+ "'";
			String[][] datas = DBTools.executeQueryWithTableHead(sql);
			Hashtable ht = DBTools.getAttributes(datas, 1);
			//用气设备+品牌+吨位+台数
			//采暖炉
			String cn = (String) ht.get("f_heatingboiler");
			if(cn !=null && !cn.equals("null"))
			{
			   String pinpai = (String) ht.get("f_heatingboiler_brand");
			   String dunwei = (String) ht.get("f_heatingboiler_tonnage");
			   String taishu = (String) ht.get("f_heatingboiler_quantity");
			   result+= cn+" "+pinpai+" "+dunwei+" "+taishu+"台,";
			}
			//茶水炉
			String cs = (String) ht.get("f_teaboiler");
			if(cs !=null && !cs.equals("null"))
			{
			   String pinpai = (String) ht.get("f_teaboiler_brand");
			   String dunwei = (String) ht.get("f_teaboiler_tonnage");
			   String taishu = (String) ht.get("f_teaboiler_quantity");
			   result+= cs+" "+pinpai+" "+dunwei+" "+taishu+"台,";
			}
			//模块炉
			String mk = (String) ht.get("f_moduleboiler");
			if(mk !=null && !mk.equals("null"))
			{
			   String pinpai = (String) ht.get("f_moduleboiler_brand");
			   String dunwei = (String) ht.get("f_moduleboiler_tonnage");
			   String taishu = (String) ht.get("f_moduleboiler_quantity");
			   result+= mk+" "+pinpai+" "+dunwei+" "+taishu+"台,";
			}
			//壁挂炉
			String bg = (String) ht.get("f_wallhungboiler");
			if(bg !=null && !bg.equals("null"))
			{
			   String pinpai = (String) ht.get("f_wallhungboiler_brand");
			   String dunwei = (String) ht.get("f_wallhungboiler_tonnage");
			   String taishu = (String) ht.get("f_wallhungboiler_quantity");
			   result+= bg+" "+pinpai+" "+dunwei+" "+taishu+"台,";
			}
			//热水器
			String rs = (String) ht.get("f_waterheater");
			if(rs !=null && !rs.equals("null"))
			{
			   String pinpai = (String) ht.get("f_waterheater_brand");
			   String dunwei = (String) ht.get("f_waterheater_tonnage");
			   String taishu = (String) ht.get("f_waterheater_quantity");
			   result+= rs+" "+pinpai+" "+dunwei+" "+taishu+"台,";
			}
			//家用灶
			String jy = (String) ht.get("f_homekitchen");
			if(jy !=null && !jy.equals("null"))
			{
			   String pinpai = (String) ht.get("f_homekitchen_brand");
			   String dunwei = (String) ht.get("f_homekitchen_tonnage");
			   String taishu = (String) ht.get("f_homekitchen_quantity");
			   result+= jy+" "+pinpai+" "+dunwei+" "+taishu+"台,";
			}
			//火眼
			String hy = (String) ht.get("f_fiereye");
			if(hy !=null && !jy.equals("null"))
			{
			   String pinpai = (String) ht.get("f_fiereye_brand");
			 
			   String taishu = (String) ht.get("f_fiereye_quantity");
			   result+= hy+" "+pinpai+" "+taishu+"个,";
			}
			//蒸车
			String zc = (String) ht.get("f_steamcars");
			if(zc !=null && !zc.equals("null"))
			{
			   String pinpai = (String) ht.get("f_steamcars_brand");
			    String taishu = (String) ht.get("f_steamcars_quantity");
			   result+= zc+" "+pinpai+" "+taishu+"台,";
			}
			//小火眼
			String xhy = (String) ht.get("f_smallfireeye");
			if(xhy !=null && !xhy.equals("null"))
			{
			   String pinpai = (String) ht.get("f_smallfireeye_brand");
			    String taishu = (String) ht.get("f_smallfireeye_quantity");
			   result+= xhy+" "+pinpai+" "+taishu+"个,";
			}
			 return result;

		} catch (Exception e) {
			return "";
		}

 
	}

	private double conver(String value) {
		if (value == null || value.equals("")) {
			return 0;
		}
		double d = Double.parseDouble(value);
		return d;
	}
}
